package com.example.cf.grouplist.activity;

import android.annotation.TargetApi;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.graphics.BitmapFactory;
import android.os.Build;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.app.NotificationCompat;
import android.view.View;

import com.example.cf.grouplist.R;

public class MainActivity extends AppCompatActivity {

    public String TAG = "TAG";
    private Notification notification;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    private void bigTextStyle() {
        NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
        builder.setContentTitle("BigTextStyle");
        builder.setContentText("BigTextStyle演示示例");
        builder.setSmallIcon(R.mipmap.ic_launcher);
        builder.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher));
        android.support.v4.app.NotificationCompat.BigTextStyle style = new android.support.v4.app.NotificationCompat.BigTextStyle();
        style.bigText("这里是点击通知后要显示的正文，可以换行可以显示很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长");
        style.setBigContentTitle("点击后的标题"); //SummaryText没什么用 可以不设置 style.setSummaryText("末尾只一行的文字内容"); builder.setStyle(style); builder.setAutoCancel(true); Intent intent = new Intent(this,SettingsActivity.class); PendingIntent pIntent = PendingIntent.getActivity(this,1,intent,0); builder.setContentIntent(pIntent); builder.setDefaults(NotificationCompat.DEFAULT_ALL); Notification notification = builder.build(); manger.notify(TYPE_BigText,notification); }
        builder.setStyle(style);
        builder.build().flags = Notification.FLAG_AUTO_CANCEL;
//        builder.build().flags = Notification.AUDIO_ATTRIBUTES_DEFAULT;
        NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        mNotificationManager.notify(0, builder.build());
    }


    public void click(View view) {
        switch (view.getId()) {
            case R.id.default_notification:
                defaultStyle();
                break;
            case R.id.big_notification:
                bigTextStyle();
                break;
            case R.id.custom_notification:
//                customStyle();
                normal();
                break;
            case R.id.group_list_bt:
                startActivity(new Intent(this,ListActivity.class));
                break;
            case R.id.photo_bt:
                startActivity(new Intent(this,PhotoActivity.class));
                break;
            case R.id.percent_layout_bt:
                startActivity(new Intent(this,PrecentActivity.class));
                break;
        }
    }

    private void normal() {
        Context context=getApplicationContext();
        NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
        Intent intentResult = new Intent(context, MainActivity.class);
//        Intent intentResult = new Intent("com.mishitu.android.manager.main");
        intentResult.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP|Intent.FLAG_ACTIVITY_NEW_TASK);
        intentResult.putExtra("viewmsg", "1");
        PendingIntent resultPendingIntent = PendingIntent.getActivity(context, 0, intentResult, PendingIntent.FLAG_UPDATE_CURRENT);

        Notification baseNF = new android.support.v4.app.NotificationCompat.Builder(context)
                .setContentTitle("新觅食兔消息")
                .setContentText("点击查看")
                .setAutoCancel(true)
                .setSmallIcon(R.mipmap.ic_launcher)
                .build();
        //发出状态栏通知
        //baseNF.defaults |= Notification.DEFAULT_SOUND;
//        baseNF.defaults |= Notification.DEFAULT_VIBRATE;
        baseNF.contentIntent = resultPendingIntent;
        nm.notify(100, baseNF);

    }

    @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
//    private void customStyle() {
//        NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
//        Notification notification = builder.getNotification();
//        notification.contentView = new RemoteViews(getPackageName(), R.layout.noti);
//        NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
//        manager.notify(1, builder.build());
//    }

    private void defaultStyle() {
        NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
        builder.setSmallIcon(R.mipmap.ic_launcher).setContentTitle("这是普通的通知").setContentText("扎世间风流事觉得风流家数到了附近阿斯利分级阿里斯顿放假啦数据的反垃圾阿斯利分级阿斯兰；附近阿里；山放假啦数据的反垃圾撒旦发");
        NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        manager.notify(1, builder.build());
    }
}